/**
 * 事务拦截器<br/>
 * 使用Aspect来实现，将会自动拦截其方法
 */
package cn.antia.db;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * User: Jair Shaw
 * Date: 2008-10-9
 * Time: 15:35:24
 */
@Aspect
public class TransactionInterceptor{
    
    @Around("execution(@AssTranscation * *(..))")
    public Object around(ProceedingJoinPoint pjp){
        try {
            TransactionUtils.begin();
            Object result = pjp.proceed();
            TransactionUtils.commit();
            return result;
        } catch (Throwable e){
            TransactionUtils.rollback(e);
            return null;
        }
    }
}
